<template>
  <el-dialog :title="'置维修'" :close-on-click-modal="false" :visible.sync="visible" v-if="visible" width="40%">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="维修时间" prop="date" style="width: 100%;">
        <el-date-picker v-model="dataForm.date" type="datetimerange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item label="维修原因" prop="desc"><el-input v-model="dataForm.desc" type="textarea" :rows="2" placeholder="维修原因"></el-input></el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      item: {},
      visible: false,
      date: [],
      dataForm: {
        id: 0,
        date: [new Date(), new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()+1,12)],
        startDate: '',
        stopDate: '',
        type: '',
        desc: ''
      },
      dataRule: {
        desc: [{ required: true, message: '原因必填', trigger: 'blur' }],
        date: [{ required: true, message: '时间必选', trigger: 'blur' }]
      }
    };
  },
  methods: {
    init(item) {
      this.item = item;
      this.visible = true;
      this.$nextTick(() => {});
    },
    // 表单提交
    dataFormSubmit() {
		console.log(this.dataForm.date)
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/hotel/thotelfloorroom/state`),
            method: 'post',
            data: this.$http.adornData({
              ids: this.item.id,
              startDate: this.dataForm.date[0],
              stopDate: this.dataForm.date[1],
              type: 4,
              desc: this.dataForm.desc
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: this.$t('Common.OperationSuccessful'),
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit('refreshDataList');
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
